<extend name="./public/frame.html"/>
<block name="content">
	<blockquote class="layui-elem-quote search">
		<div class="layui-inline">
			<input type="text" class="layui-input date" readonly id="start" placeholder="车辆注册时间-起">
		</div>
		<div class="layui-inline">
			<input type="text" class="layui-input date" readonly id="end" placeholder="车辆注册时间-止">
		</div>
		<div class="layui-inline">
			<input type="text" lay-verify="required|title" required placeholder="请输入手机号"  class="layui-input" id="driver_phone">
		</div>
		<div class="layui-inline">
			<input type="text" placeholder="车牌号"  class="layui-input" id="car_plate">
		</div>
		<div class="layui-inline">
			<button class="layui-btn" data-type="search">搜索</button>
		</div>
	</blockquote>
	<table class="layui-table" lay-data="{cellMinWidth: 80, height:'auto', url:'{:url('car/index')}',where:{driver_type:<?php echo $driver_type;?>}, page: true,limit: 10, id:'car'}"
		   lay-filter="car">
		<thead>
		<tr>
			<th lay-data="{checkbox:true,fixed: true}"></th>
			<th lay-data="{field:'car_id', width:80, fixed: true, align:'center'}">ID</th>
			<th lay-data="{field:'driver_name', width:100, align:'center'}">姓名</th>
			<th lay-data="{field:'driver_phone', width:120, align:'center'}">手机号</th>
			<th lay-data="{field:'car_plate', width:150, align:'center'}">车牌号</th>
			<th lay-data="{field:'car_brand', width:150, align:'center'}">车辆信息</th>
			<th lay-data="{field:'color', width:120, align:'center'}">颜色</th>
			<th lay-data="{field:'owner', width:120, align:'center'}">车辆所有人</th>
			<th lay-data="{field:'register_at', width:130, align:'center'}">车辆注册时间</th>
			<th lay-data="{field:'their_name', width:130, align:'center'}">所属运力</th>
			<th lay-data="{fixed:'right', toolbar: '#barDemo', width:270, align:'center'}">操作</th>
		</tr>
		</thead>
	</table>

	<script type="text/html" id="barDemo">
		<a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
		<!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="jianguan">车辆备案</a>-->
		<!--<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="baoxian">车辆保险</a>-->
		{{#if(d.is_supplement == 2) { }}
		<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="supplement">资料补录</a>
		{{# } else if(d.is_supplement == 1) { }}<a class="layui-btn layui-btn-xs" lay-event="supplement">已补录</a>
		{{#}}}
		<!--<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>-->
	</script>

	<script type="application/javascript">
		layui.use(['table','laytpl','laydate'], function () {
			var table = layui.table
				,laydate = layui.laydate;
			lay('.date').each(function () {
				laydate.render({elem: this, type: 'date', trigger: 'click'});
			});

			//监听工具条
			table.on('tool(car)', function (obj) {
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; //获得当前行 tr 的DOM对象
				var car_id = data.car_id;
				var driver_id = data.driver_id;
				if (layEvent === 'del') {
					layer.confirm('确定删除吗?', function (index) {
						var url = "{:U('ajax_del')}";
						$.post(url, {'car_id': car_id}, function (data) {
							console.log(data);
						}, 'json');
						layer.close(index);
					});
				}
				else if(layEvent === 'detail'){
					var uid = data.uid;
					layer.open({
						type: 2,
						title: '车辆信息',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/car/detail","car_id=")}' + car_id //iframe的url
					});
				}
				else if(layEvent === 'edit'){
					var uid = data.uid;
					layer.open({
						type: 2,
						title: '车辆编辑',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/driver/edit","driver_id=")}' + driver_id //iframe的url
					});
				}
				/*else if(layEvent === 'jianguan'){
					var uid = data.uid;
					layer.open({
						type: 2,
						title: '司机信息查看',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/system/clba","car_id=")}' + car_id
					});
				}*/
				else if(layEvent === 'baoxian'){
					var uid = data.uid;
					layer.open({
						type: 2,
						title: '车辆保险',
						shadeClose: true,
						shade: 0.8,
						area: ['100%', '100%'],
						content: '{:url("/admin/system/clbx","car_id=")}' + car_id
					});
				}
                else if(layEvent === 'supplement'){
                    var uid = data.uid;
                    layer.open({
                        type: 2,
                        title: '车辆补录信息查看',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['100%', '100%'],
                        content: '{:url("/admin/car/supplement","car_id=")}' + car_id
                    });
                }
			});

			var $ = layui.jquery, active = {
				search: function () {
					var start = $('#start').val();
					var end = $('#end').val();
					var driver_phone = $.trim($('#driver_phone').val());
					var car_plate = $.trim($('#car_plate').val());
					table.reload('car', {
						url: '/admin/car/index',
						where: {
							start : start,
							end : end,
							driver_phone : driver_phone,
							car_plate:car_plate
						}
					});
				}
			};
			$('.layui-btn').on('click', function () {
				var type = $(this).data('type');
				active[type] ? active[type].call(this) : '';
			});
		});

	</script>
</block>
